#ifndef QUERY_H
#define QUERY_H
#include"WordQuery.h"
class Query{
    //在Query中使用~操作符构造NotQuery
    friend Query operator~(const Query &);
    //在Query中使用|操作符构造OrQuery
    friend Query operator| (const Query&, const Query&);
    //在Query中使用&操作符构造AndQuery
    friend Query operator& (const Query&, const Query&);

    public:
        // 构建一个新的WordQuery
        Query(const string &s): q(new WordQuery(s)){
            // if(DEBUG) std::cout << "Query::Query(const std::string& s) where s=" + s + "\n";
        }   
        // 接口函数: 调用对应的Query_base操作
        QueryResult eval(const TextQuery &t) const{ return q->eval(t); }
        string rep() const {return q->rep();}
    private:
        Query(shared_ptr<Query_base> query) : q(query) {
        }
        shared_ptr<Query_base> q;
};

inline std::ostream&
operator<< (std::ostream& os, const Query& query)
{
	// make a virtual call through its Query_base pointer to rep();
	return os << query.rep();
}

#include "AndQuery.h"
#include "OrQuery.h"
#include "NotQuery.h"
#endif // QUERY_H